using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Speedball2 {
  public class BounceDomes {
    private Entity _entityTop = new Entity (Game.AtariDisk, Game.AtariRamToDisk (0x4B0A));
    private Entity _entityBottom = new Entity (Game.AtariDisk, Game.AtariRamToDisk (0x4B34));

    public BounceDomes () {
    }

    public void CheckHit (Match match) {
      if (match.EntityHoldingBall != null)
        return;
      if (match.EntityBall._spriteIndex > 2)
        return;
      CheckHitOne (match, _entityTop);
      CheckHitOne (match, _entityBottom);
    }

    private void CheckHitOne (Match match, Entity bounceDome) {
      Entity ball = match.EntityBall;
      int deltaY = Math.Abs (ball._terrainXY.Y - bounceDome._terrainXY.Y);
      if (deltaY > 16)
        return;
      int deltaX = Math.Abs (ball._terrainXY.X - bounceDome._terrainXY.X);
      if (deltaX > 16)
        return;
      Point vector;
      if (bounceDome.CalcVector (ball._terrainXY, out vector) > 16)
        return;
      bounceDome._opcodeIndex = 0;
      DirBits dirBits = bounceDome.GetDirBitsToTargetBetter (ball._terrainXY);
      if (dirBits.HasNoDirection)
        return;
      ball._dir = Entity.GetDirFromDirBits (dirBits);
      ball._velocityXY = Match.GetVelocityXYFromDir (ball._dir, 8);
      ball._opcodeIndex = 0;
      match.SetBallSpeedFromThr (match.PlayerThrower._attributes._thr);
      match.IncScoreWithBonusPoints (match.PlayerThrower.Bit3_IsTeam1_IsElectrobounced, 2);
      match.DrawStatusScores ();
    }

    public Entity EntityTop {
      get {
        return (_entityTop);
      }
    }

    public Entity EntityBottom {
      get {
        return (_entityBottom);
      }
    }
  }
}
